﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VentaElectrodomesticos.Negocio;
using VentaElectrodomesticos.Datos.Dto;
using VentaElectrodomesticos.Contrato;
using VentaElectrodomesticos.GUI.Base;

namespace VentaElectrodomesticos.ClientesPremium
{
    public partial class FormClientesPremium : BaseValidaciones
    {
        private static FormClientesPremium instance;
        ClienteNegocio clienteNegocio;

        public FormClientesPremium()
        {
            InitializeComponent();

            clienteNegocio = new ClienteNegocio();
            this.comboSucursal.Items.AddRange(new SucursalNegocio().getAll().ToArray());
            this.comboSucursal.DisplayMember = "Direccion";
            this.comboSucursal.ValueMember = "Id";
            this.comboSucursal.SelectedIndex = 0;
        }

        private void setList(List<ClientePremiumDTO> list)
        {
            BindingSource bindingSource = new BindingSource();
            bindingSource.DataSource = list;
            this.dataGridView1.DataSource = bindingSource;

            this.dataGridView1.Columns["nombre"].HeaderText = "Nombre";
            this.dataGridView1.Columns["apellido"].HeaderText = "Apellido";
            this.dataGridView1.Columns["dni"].HeaderText = "Dni";
            this.dataGridView1.Columns["monto"].HeaderText = "Monto";
            this.dataGridView1.Columns["totalProd"].HeaderText = "Total de productos";
            this.dataGridView1.Columns["fechaUltComp"].HeaderText = "Fecha ultima compra";
            this.dataGridView1.Columns["dniEmp"].HeaderText = "Dni del empleado";

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.setList(clienteNegocio.getClientesPremium((long)((Sucursal)this.comboSucursal.SelectedItem).Id, Convert.ToInt32(this.comboAnios.Value)));
        }

        internal static FormClientesPremium getInstance()
        {
            if (instance == null)
                instance = new FormClientesPremium();
            instance.BringToFront();
            return instance;
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            instance = null;
            base.OnClosing(e);
        }
    }
}
